<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<!-- ..//JQuery Source\\.. -->
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<!-- ..//JavaScript Code for this page\\.. -->
<script type="text/javascript">
$(document).ready(function(){
	$("#login_frm").submit(function(){
		
			var email = $("#email");
			var pass = $("#pass");
			var confirmpass = $("#confirmpass");
			var username = $("#username");
			
			if(email.val() == "" || pass.val() == "" || email == null || pass == null || confirmpass.val() == ""){
				$("#msgbox").fadeTo(200,0.1,
					function(){
			        	$(this).html('邮箱或者密码不能为空!').removeClass().addClass('myerror').fadeTo(900,1);
			        });
			        return false;
			}
			
			if(confirmpass.val() != pass.val() ){
				$("#msgbox").fadeTo(200,0.1,
					function(){
			        	$(this).html('两次输入的密码不一致!').removeClass().addClass('myerror').fadeTo(900,1);
			            document.all.pass.value = "";
			            document.all.confirmpass.value = "";
			        });
			        return false;
			}
			
        $("#msgbox").removeClass().addClass('myinfo').text('正在验证你的注册信息...').fadeIn(1000);
        
		this.timer = setTimeout(function () {
			$.ajax({
	          	url: 'resgist.j',
	          	data: "email="+email.val()+"&pass="+pass.val()+"&username="+username.val(),
	          	type: 'post',
	   			success: function(msg){
					if(msg.result != "ERROR") {	
						$("#msgbox").html('注册成功，正在登录...').addClass('myinfo').fadeTo(900,1,
		                  function()
		                  {
		                     //redirect to secure page
		                     document.location='<%=request.getContextPath()%>/main.j?username='+msg.result;
		                  });
					}
					else{
						$("#msgbox").fadeTo(200,0.1,
							function(){
			                  $(this).html('对不起，您输入邮箱已经被占用!').removeClass().addClass('myerror').fadeTo(900,1);
			                });
					}
				}
			});
		}, 200);
		return false;
		});		
});
</script>
<link href="<%=request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>用户注册</title>
</head>
<body>
<!-- table align="center" cellSpacing="1" cellPadding="1" background="/pictures/dqy2_081.jpg" width="100%" height="100%"><tr><td -->
<form name="login_frm" id="login_frm" action="" method="post" backgroundColor="#FAFBFF">
	<div id="login_box" >
	  <div id="login_header"><b>用户注册</b></div>
	  <div id="form_val">
	    <div class="label">邮箱：</div>
	    <div class="control"><input type="text" name="email" id="email"/>&nbsp;<font color="red">*</font></div>
	    <div class="label">用户昵称：</div>
	    <div class="control"><input type="text" name="username" id="username"/></div>
	    <div class="label">密码：</div>
	    <div class="control"><input type="password" name="pass" id="pass"/>&nbsp;<font color="red">*</font></div>
	    <div class="label">确认密码：</div>
	    <div class="control"><input type="password" name="confirmpass" id="confirmpass"/>&nbsp;<font color="red">*</font></div>
	    <div style="clear:both;height:0px;"></div>
	  	<div id="msgbox"></div>
	  </div>
	  <div id="login_footer">
	    <label>
	    <input type="reset" name="reset" id="reset" value="重置" class="send_button" />
	    </label>
	    <label>
	    <input type="submit" name="regist" id="regist" value="注册" class="send_button" />
	    </label>
	  </div>
	</div>
</form>
</body>
</html>